package eoeProject.edenOfEast.utils;

import java.sql.ResultSet;
import java.sql.SQLException;

import eoeProject.edenOfEast.bean.EOEUserBean;
import eoeProject.edenOfEast.core.DBConnector;
import eoeProject.edenOfEast.core.SQLMaker;
import eoeProject.edenOfEast.dataBase.DB_EOE_USER;

public class EOEUtils {

	public static String getUserName(Integer id) {
		String value = "";
		SQLMaker sql = new SQLMaker(DB_EOE_USER.TABLE_NAME,
				SQLMaker.SQL_TYPE_SELECT);
		sql.addExpEquals(DB_EOE_USER.USER_ID, id);
		ResultSet rs = DBConnector.getInstance().get(sql.getSQL());
		try {
			if (rs.next()) {
				value = rs.getString(DB_EOE_USER.USER_NAME);
			}
			rs.close();
		} catch (SQLException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
			return null;
		}
		return value;
	}

	public static EOEUserBean getUserBean(Integer id) {
		EOEUserBean userBeam = new EOEUserBean();

		SQLMaker sql = new SQLMaker(DB_EOE_USER.TABLE_NAME,
				SQLMaker.SQL_TYPE_SELECT);
		sql.addExpEquals(DB_EOE_USER.USER_ID, id);
		ResultSet rs = DBConnector.getInstance().get(sql.getSQL());
		try {
			if (rs.next()) {
				userBeam.setUserId(rs.getInt(DB_EOE_USER.USER_ID));
				userBeam.setUserName(rs.getString(DB_EOE_USER.USER_NAME));
				userBeam.setEmail(rs.getString(DB_EOE_USER.EMAIL));
				userBeam.setCreateDate(rs.getTimestamp(DB_EOE_USER.CREATE_DATE));
				userBeam.setUpdateDate(rs.getTimestamp(DB_EOE_USER.UPDATE_DATE));
			}
			rs.close();
		} catch (SQLException e) {
			// TODO 自動生成された catch ブロック
			System.out.println("TacticsUtilException: " + e.getMessage());
			return null;
		}
		return userBeam;
	}

}
